package org.auth.service.controller;

import java.security.Principal;

import org.auth.service.dao.BaseUserDAO;
import org.auth.service.model.BaseUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    public BaseUserDAO userMapper;
    
    @Autowired
    @Qualifier("consumerTokenServices")
    private ConsumerTokenServices consumerTokenServices;

    @GetMapping("getByName")
    public BaseUser getByName(){
        return userMapper.selectByUserName("zhangjian");
    }

    /**
     * 获取授权的用户信息
     * @param principal 当前用户
     * @return 授权信息
     */
    @GetMapping("current/get")
    public Principal user(Principal principal){
    	return principal;
    }
    
    
    /**
     * 退出登录,并清除redis中的token
     **/
    @GetMapping("/remove/token/{accessToken}")
    public Boolean removeToken(@PathVariable String accessToken)
    {
    	System.out.println(accessToken);
        return consumerTokenServices.revokeToken(accessToken);
    }


}
